package com.txby.dplus.common.annomapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.transaction.annotation.Transactional;

/**
 * MyBatis 全注解CRUD基础接口
* @ClassName: BaseMapperCRUD 
* @Description: TODO （描述）
* @author 作者 jacking
* @date 2017年6月23日 上午11:52:20 
* @param <T>
 */

public interface BaseMapperAnnCRUD<T> extends BaseMapperAnnotation{
	/**
	 * 根据对象查询总数量
	 * @param obj
	 * @return
	 */
	@SelectProvider(type = ProviderTemplate.class,method = "count")
	public int count(Class clazz);
	/**
	 * 根据id,查询设置对象类型
	 * @param clazz
	 * @param id
	 * @return
	 */
	@SelectProvider(type = ProviderTemplate.class,method = "selectById")
	public Map selectById(Class clazz,String id);
	/**
	 * 根据字段和值查询,条件可能and || or
	 * @param clazz
	 * @param param
	 * @return
	 */
	@SelectProvider(type = ProviderTemplate.class,method = "selectByProperty")
	public List<Map> selectByProperty(Class clazz,@Param("pojo")Map param,boolean isAndOr);
	
	
	/**
	 * 根据字段和值查询，like查询 ，条件可能and || or
	 * @param clazz
	 * @param param
	 * @param isAndOr
	 * @return
	 */
	@SelectProvider(type = ProviderTemplate.class,method = "selectLikeByProperty")
	public List<Map> selectLikeByProperty(Class clazz,@Param("pojo")Map param,boolean isAndOr);
	/**
	 * @Description: select 根据对象查询 
	 * @param obj
	 * @return
	 */
	@SelectProvider(type = ProviderTemplate.class,method = "select")
	public T select(@Param("pojo")T obj);
	/**
	 * 保存对象返回持久化对象
	 * @Description: TODO(这里用一句话描述这个方法的作用) 
	 * @param obj
	 * @return
	 */
	@SelectProvider(type = ProviderTemplate.class,method = "save")
	@Transactional
	public Map save(@Param("pojo")T obj);
	/**
	 * @Description: select 根据对象查询所有 
	 * @param obj
	 * @return
	 */
	@SelectProvider(type = ProviderTemplate.class,method = "selectAll")
	public List<Map>  selectAll(Class clazz);
	
	/**
	 * Insert语句从ProviderTemplate类中生成
	 * 返回mysql自增id_
	 * @param obj
	 */
	@InsertProvider(type = ProviderTemplate.class,method = "insert")
	@Options(useGeneratedKeys = true, keyProperty = "pojo.id_")
	@Transactional
	public int insert(@Param("pojo")T obj);
	
	
	/**
	 * Update语句从ProviderTemplate类中生成
	 * @param obj
	 */
	@UpdateProvider(type = ProviderTemplate.class,method = "update")
	@Transactional
	public int update(@Param("pojo")T obj);
	
	/**
	 * Delete语句从ProviderTemplate类中生成
	 * @param obj
	 */
	@DeleteProvider(type = ProviderTemplate.class,method = "delete")
	@Transactional
	public int delete(@Param("pojo")T obj);
	/**
	 * 根据id删除
	 * Delete语句从ProviderTemplate类中生成
	 * @param obj
	 */
	@DeleteProvider(type = ProviderTemplate.class,method = "deleteById")
	@Transactional
	public int deleteById(Class clazz,String id);

	
}
